package com.miyake.dsp.osa.lab.wrapper;

import com.miyake.dsp.ComplexArray;
import com.miyake.dsp.common.CommonTool;
import com.miyake.dsp.generator.GaussGenerator;
import com.miyake.dsp.generator.GaussSetting;
import com.miyake.dsp.osa.lab.Calculator;
import com.miyake.dsp.osa.lab.Convolution2;
import com.miyake.dsp.osa.lab.GaussianFilterSetting;
import com.miyake.dsp.osa.lab.LabUiAnnotation;
@LabUiAnnotation(caption="Gaussian Filter")
public class GaussianFilterWrapper extends Calculator {
	public static final String INPUT = "Input";
	public static final String OUTPUT = "Output";
	public static final String OUTPUT_SHAPE = "Shape";
	private GaussSetting setting;
	
	public GaussianFilterWrapper(GaussSetting setting) {
		this.setting = setting;
		initInput(INPUT);
		initOutput(OUTPUT);
		initOutput(OUTPUT_SHAPE);
	}
	
	
	@Override
	public void process() {
		
		GaussGenerator gauss = new GaussGenerator(
				setting.getSigma(), 0.0, setting.getSamples(), setting.getN());
		double[] g = gauss.getY();
		double integral = CommonTool.getIntegral(g);
		double[] ret = new double[g.length];
		for (int i = 0; i < g.length; i++) {
			ret[i] = g[i] / integral;
		}
		
		if (this.getInput(INPUT) != null) {
			setOutput(OUTPUT, new Convolution2().getResult(
					this.getInput(INPUT).getRealPart(), 
					new ComplexArray(ret).getRealPart()));
		}
		
		setOutput(OUTPUT_SHAPE, ret);
	}

	@Override
	public Object getSetting() {
		return this.setting;
	}

}
